//
//  WelcomeViewController.m
//  HappinessTrip
//
//  Created by dllo on 15/10/17.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "WelcomeViewController.h"
#import "ViewController.h"
#import "Fit.h"

@interface WelcomeViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)NSArray *array;

@end

@implementation WelcomeViewController
-(void)dealloc
{
    [_scrollView release];
    [_array release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}
-(void)loadView
{
    [super loadView];
    self.array = @[@"huanying1", @"huanying2", @"huanying3"];
    self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    _scrollView.contentSize = CGSizeMake(_array.count * self.view.frame.size.width, self.view.frame.size.height);
    _scrollView.contentOffset = CGPointMake(0, 0);
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    for (NSInteger i = 0; i < _array.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [UIImage imageNamed:_array[i]];
        [_scrollView addSubview:imageView];
        [imageView release];
    }
    [self.view addSubview:_scrollView];
    [_scrollView release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(100 * W, 500 * H, 175 * W, 40 * H);
    button.layer.cornerRadius = 20;
    button.layer.borderWidth = 2;
    button.layer.borderColor = [[UIColor colorWithRed:0.56 green:0.53 blue:0.93 alpha:1] CGColor];
    button.backgroundColor = [UIColor clearColor];
    [button addTarget:self action:@selector(jumpAction) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"进入心情" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:0.56 green:0.53 blue:0.93 alpha:1] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:button];
}
-(void)jumpAction
{
    _tabBarController.modalTransitionStyle =  UIModalTransitionStyleCrossDissolve;
    [self presentViewController:_tabBarController animated:YES completion:nil];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_scrollView.contentOffset.x > (_array.count - 1)* self.view.frame.size.width + 50) {
        [self jumpAction];
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
